let count = localStorage.getItem('count');
let ws;
let user_count = {
    username: '',
    count: '',
};
let user_counts = [];

function new_websocket() {
    let nws = new WebSocket('ws://' + window.location.host + '/chat/count'), ws;
    nws.onmessage = function (e) {
        count = e.data;
        localStorage.setItem('count', count);
    }
    nws.onclose = function () {
        ws = new_websocket();
    }
    nws.addEventListener('open', get_count);
    return nws;
}

function get_count() {
    if(ws.readyState === ws.OPEN) {
        ws.send('');
    }
    setTimeout('get_count()', 1000);
}

if (count === null) {
    count = '0';
}

ws = new_websocket();